
/**
 * 行为转发类
 * @constructor
 */
function RoomDetail(){

    /**
     * 动作转发
     * @param action
     * @param msg
     */
    this.getAction=function (msg) {
        message= JSON.parse(msg.data);
        var state=this.checkStatus(message.head);
        if(state==false){
            layer.msg(message.msg);
            return;
        }

        switch (message.head){

            //获取详细信息
            case ProtocolApi.Protocol['DDZ_GET_ROOM_DETAIL']:
                this.getRoomDetail(message.msg);
                break;

        }
    };

    this.getRoomDetail=function (msg){
        layer.msg('玩家加入房间');
        var RoomID=msg.roomID;
        var roomStatus=msg.roomStatus;
        var playerNumber=msg.playerNumber;
        var playerList=msg.playerList;
        var content="<div>【房间ID："+RoomID+"】  ";
        content+="【房间人数："+playerNumber+"】  ";
        content+="【房间状态："+(roomStatus==1 ? "游戏中" :"等待")+"】";
        if(roomStatus==0){
            content+="<button id='reday' style='padding: 2px; width: 100px;'>立即准备</button></div>";
        }else{
            content+="</div>";
        }
        var head=content;
        $('#head').html(content);
        content='';
        $.each(playerList,function(index,value,array){
            content+="<div class='playerInfo'>";
            content+="<div>玩家ID："+playerList[index]['user_id']+"</div><div>玩家昵称："+playerList[index]['nickname']+"</div>";
            content+="</div>";
        });
        $('#reday').click(function (){
            ws.send();
        });
        $('#head').html(head+content);

    };


    /**
     * 状态码检测
     * @param status
     * @returns {boolean}
     */
    this.checkStatus=function (status){
        if(status==ProtocolApi.Protocol['TOKEN_ERROR']){

            localStorage.setItem('PhpGameSocketToken','');
            localStorage.setItem('PhpGameSocketTokenTime','');
            return false;
        }

        if(status===ProtocolApi.Protocol['GAME_ERROR']){
            return false;
        }
        return true;
    };



}